//
//  ZPZNetRequest.m
//  项目2网络封装
//
//  Created by rimi on 16/7/22.
//  Copyright © 2016年 周伦. All rights reserved.
//

#import "ZPZNetRequest.h"
#import "ZPZNetRequest.h"
#import "AFNetworking.h"

#define BASE_URL @"http://nmzh.rimiedu.com/rimicms/resources/"


@implementation ZPZNetRequest
+(void)sendRequestByParameters:(NSDictionary *)parameters
                        Method:(NSString *)method
                   requestType:(ZLAPIRequestType )requestType
                     Comletion:(ZLReqComletion )comletion{
    NSString *url = [NSString stringWithFormat:@"%@%@",BASE_URL,method];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 10;
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/html",@"text/javascript", nil];
    switch (requestType) {
        case ZLApRequestPost:
        {
            [manager POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                if (comletion) {
                    comletion(responseObject,1);
                }
                
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                if (comletion) {
                    comletion(error.description,0);
                }
                
            }];
            
        }
            break;
            
        default:
            break;
    }
    
    
}
//返回json格式的字典
+(NSDictionary *)getParametersPaeames:(NSDictionary *)paeames{
    NSDictionary *muDictionary = [NSDictionary dictionary];
        if (![LStringUtils isTextEmpty:[LStringUtils jsonStringWithParameters:paeames]]) {
    NSString *string = [LStringUtils jsonStringWithParameters:paeames];
    muDictionary = [NSDictionary dictionaryWithObject:string forKey:@"paramJson"];
        }
    return muDictionary;
    
}

@end
